home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CONTAS2.PAK / CNTRITEM.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  187 lines

  1. // CntrItem.cpp : implementation of the CContainerItem class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Contain.h"
  6.  
  7. #include "ContrDoc.h"
  8. #include "CntrItem.h"
  9. #include "ContrVw.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CContainerItem implementation
  19.  
  20. IMPLEMENT_SERIAL(CContainerItem, COleClientItem, 0)
  21.  
  22. CContainerItem::CContainerItem(CContainerDoc* pContainer)
  23.     : COleClientItem(pContainer)
  24. {
  25.     // TODO: add one-time construction code here
  26.     m_rect.SetRect(10, 10, 50, 50);
  27. }
  28.  
  29. CContainerItem::~CContainerItem()
  30. {
  31.     // TODO: add cleanup code here
  32.     
  33. }
  34.  
  35. void CContainerItem::InvalidateItem()
  36. {
  37.     GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_ITEM, this);
  38. }
  39.  
  40. void CContainerItem::UpdateFromServerExtent()
  41. {
  42.     CSize size;
  43.     if (GetCachedExtent(&size))
  44.     {
  45.         // OLE returns the extent in HIMETRIC units -- we need pixels
  46.         CClientDC dc(NULL);
  47.         dc.HIMETRICtoDP(&size);
  48.  
  49.         // Only invalidate if it has actually changed, and also
  50.         // only if it is not in-place active.  When in-place active, the
  51.         // container item size should sync with the "window size" of the
  52.         // object.  Only when not in-place active should the container 
  53.         // item size should sync with the natural size of the object.
  54.  
  55.         if ((size != m_rect.Size()) && !IsInPlaceActive())
  56.         {
  57.             // invalidate old, update, invalidate new
  58.             InvalidateItem();
  59.             m_rect.bottom = m_rect.top + size.cy;
  60.             m_rect.right = m_rect.left + size.cx;
  61.             InvalidateItem();
  62.  
  63.             // mark document as modified
  64.             GetDocument()->SetModifiedFlag();
  65.         }
  66.     }
  67. }
  68.  
  69. void CContainerItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
  70. {
  71.     ASSERT_VALID(this);
  72.  
  73.     COleClientItem::OnChange(nCode, dwParam);
  74.  
  75.     // When an item is being edited (either in-place or fully open)
  76.     //  it sends OnChange notifications for changes in the state of the
  77.     //  item or visual appearance of its content.
  78.     switch (nCode)
  79.     {
  80.     case OLE_CHANGED:
  81.         InvalidateItem();
  82.         UpdateFromServerExtent();
  83.         break;
  84.     case OLE_CHANGED_STATE:
  85.     case OLE_CHANGED_ASPECT:
  86.         InvalidateItem();
  87.         break;
  88.     }
  89.  
  90. }
  91.  
  92. BOOL CContainerItem::OnChangeItemPosition(const CRect& rectPos)
  93. {
  94.     ASSERT_VALID(this);
  95.  
  96.     // During in-place activation CContainerItem::OnChangeItemPosition
  97.     //  is called by the server to change the position of the in-place
  98.     //  window.  Usually, this is a result of the data in the server
  99.     //  document changing such that the extent has changed or as a result
  100.     //  of in-place resizing.
  101.     //
  102.     // The default here is to call the base class, which will call
  103.     //  COleClientItem::SetItemRects to move the item
  104.     //  to the new position.
  105.  
  106.     if (!COleClientItem::OnChangeItemPosition(rectPos))
  107.         return FALSE;
  108.     InvalidateItem();
  109.     m_rect = rectPos;
  110.     InvalidateItem();
  111.  
  112.     // mark document as dirty
  113.     GetDocument()->SetModifiedFlag();
  114.  
  115.     return TRUE;
  116. }
  117.  
  118. void CContainerItem::OnGetItemPosition(CRect& rPosition)
  119. {
  120.     ASSERT_VALID(this);
  121.     // return rect relative to client area of view
  122.     rPosition = m_rect;
  123. }
  124.  
  125. void CContainerItem::OnActivate()
  126. {
  127.     // allow only one inplace active item per frame
  128.     CView* pView = GetActiveView();
  129.     ASSERT_VALID(pView);
  130.     COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
  131.     if (pItem != NULL && pItem != this)
  132.         pItem->Close();
  133.  
  134.     COleClientItem::OnActivate();
  135. }
  136.  
  137. void CContainerItem::OnDeactivateUI(BOOL bUndoable)
  138. {
  139.     COleClientItem::OnDeactivateUI(bUndoable);
  140.  
  141.     // hide the object if it is not an outside-in object
  142.     DWORD dwMisc = 0;
  143.     m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
  144.     if (dwMisc & OLEMISC_INSIDEOUT)
  145.         DoVerb(OLEIVERB_HIDE, NULL);
  146. }
  147.  
  148. void CContainerItem::Serialize(CArchive& ar)
  149. {
  150.     ASSERT_VALID(this);
  151.  
  152.     // Call base class first to read in COleClientItem data.
  153.     // Since this sets up the m_pDocument pointer returned from
  154.     //  CContainerItem::GetDocument, it is a good idea to call
  155.     //  the base class Serialize first.
  156.     COleClientItem::Serialize(ar);
  157.  
  158.     // now store/retrieve data specific to CContainerItem
  159.     if (ar.IsStoring())
  160.     {
  161.         // TODO: add storing code here
  162.         ar << m_rect;
  163.     }
  164.     else
  165.     {
  166.         // TODO: add loading code here
  167.         ar >> m_rect;
  168.     }
  169. }
  170.  
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CContainerItem diagnostics
  173.  
  174. #ifdef _DEBUG
  175. void CContainerItem::AssertValid() const
  176. {
  177.     COleClientItem::AssertValid();
  178. }
  179.  
  180. void CContainerItem::Dump(CDumpContext& dc) const
  181. {
  182.     COleClientItem::Dump(dc);
  183. }
  184. #endif
  185.  
  186. /////////////////////////////////////////////////////////////////////////////
  187.